<?php

function GMRequest($data)
{
	$privatekey = file_get_contents('./key.pem');

	$url = 'https://gmasiatech.net/merchant/process.php';

	$res = openssl_pkey_get_private($privatekey);
	$ssl_sign = '';

	if (openssl_sign(md5(json_encode($data)), $ssl_sign, $res)){
		$ssl_sign = base64_encode($ssl_sign);
	}

	$data['ssl_sign'] = $ssl_sign;

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_POST, 1 );
	curl_setopt($curl, CURLOPT_HEADER, 0);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,false);
	curl_setopt($curl, CURLOPT_SSLKEY, realpath('./key.pem'));
	curl_setopt($curl, CURLOPT_SSLKEYTYPE,'PEM');

	curl_setopt($curl, CURLOPT_POSTFIELDS, $data );
	$response = curl_exec($curl);
	curl_close($curl);

	return $response;
}

$merchantId = 'G2P55121d4dd4251';

$data = array(
	'method' => 'reqGetBankAccount',
	'merchantId' => $merchantId,
);

$responseAccount = GMRequest($data);

?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
	<title></title>

	<style type="text/css">
		table{
			width:100%;
			margin:0px auto;
			font:Georgia 11px;
			color:#333333;
			text-align:center;
			border-collapse:collapse;
		}
		th,td{
			border:1px solid #333;
			padding:5px;
		}
		
    </style>
  </head>

  <body>
  <h2>帐户信息</h2>
   <table>
	<?php
	if($responseAccount && ($response = json_decode($responseAccount)) && $response->code == 1) 
	{
		if($response->data) 
		{
			//table header
			$header = isset($response->data[0]) ? array_keys((array)$response->data[0]) : array();
			if($header) {
				echo '<tr>';
				foreach($header as $k=>$v) {
					echo '<th>'.$v.'</th>';
				}
				echo '</tr>';
			}

			foreach($response->data as $k=>$v) {
			echo '<tr>';

				$bank = get_object_vars($v);
				if($bank) {
					foreach($bank as $a=>$b) {
						echo '<td>' . $b . '</td>';
					}
				}
				echo '</tr>';
			}
		} else {
			echo '<tr><td>没有找到帐户</td></tr>';
		}
	} else {
		echo '<tr><td>Code: '.$response->code.'</td></tr>';
	}
	?>

  
</table>
</body>
</html>
